import jwt


class Jwt:
    def __init__(self):
        self.SECRET_KEY='asfsf!#$#$@$#^%#$sdfwtwa134342432323fffwf'

    #加密
    def encode_jwt(self,data):
        token = jwt.encode(data,self.SECRET_KEY,algorithm='HS256')
        return token

    #解密
    def decode_jwt(self,token):
        data = jwt.decode(token,self.SECRET_KEY,algorithms='HS256')
        #再从新加密

        newtoken = jwt.encode(data,self.SECRET_KEY,algorithm='HS256')
        return newtoken

    #对比
    def checx_token(self,token,newtoken):
        if token == newtoken:
            return True
        return False

myjwt = Jwt()
# token = myjwt.encode_jwt({'data':{'name':'abc'}})
# print(token)
# token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJkYXRhIjp7Im5hbWUiOiJhYmMifX0.Ck-Il6JwPJu-ZAQr4zXm7oi91iqnKXrWEzOrplPqWAI'
# print(myjwt.decode_jwt(token))